package org.pictual.service;

import org.apache.log4j.Logger;
import org.pictual.business.dao.DAOFactory;
import org.pictual.business.dao.MySQLDAOFactory;
import org.pictual.business.dao.SequenceGeneratorDAO;
import org.pictual.business.dao.exceptions.DAOException;
import org.pictual.business.vo.DefinicionVO;


public class DefinicionDelegateImpl implements DefinicionDelegate{

	private static DefinicionDelegateImpl _instance = null;
	protected static Logger log= Logger.getLogger(DefinicionDelegateImpl.class);
	protected SequenceGeneratorDAO sequenceGeneratorDAO;
	
	private DefinicionDelegateImpl(){}

	public static DefinicionDelegateImpl getInstance(){
		if(_instance==null){
    		_instance = new DefinicionDelegateImpl();
    	}
        return _instance;
	}

	public DefinicionVO readDefinicion(int palabra_id, int idioma_origen, int idioma_destino) {
		try {
			DefinicionVO definicionVO = DAOFactory.getDAOFactory(DAOFactory.MYSQL).getDefinicionDAO().readDefinicion(palabra_id, idioma_origen, idioma_destino);
//			MySQLDAOFactory.closeConnection();
			return definicionVO;
					
		} catch (DAOException e) {
			log.error("readDefinicion: DAOException: ",e);
		}
		return null;
	}

	public void insertDefinicion(DefinicionVO definicion) {
		try {
			DAOFactory.getDAOFactory(DAOFactory.MYSQL).getDefinicionDAO().insertDefinicion(definicion);
//			MySQLDAOFactory.closeConnection();
		} catch (DAOException e) {
			log.error("insertDefinicion: DAOException: ",e);
		}
		
	}
	
	public void setSequenceGeneratorDAO(SequenceGeneratorDAO sequenceGeneratorDAO) {
		this.sequenceGeneratorDAO = sequenceGeneratorDAO;
	}
}
